package com.spa.infrastructure.service.permission;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.spa.infrastructure.enums.dict.base.RequestSourceEnum;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * sa-token 权限管理实现类
 *
 */
@Component
public class SaPermission implements StpInterface{
    /**
     * 获取菜单权限列表
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<String> list = new ArrayList<String>();
        if(RequestSourceEnum.Member.getCode().equals(StpUtil.getLoginDevice()) ){
            list.add(RequestSourceEnum.Member.getCode());
        }
        if(RequestSourceEnum.Admin.getCode().equals(StpUtil.getLoginDevice()) ){
            list.add(RequestSourceEnum.Admin.getCode());
        }
        if(RequestSourceEnum.Massagist.getCode().equals(StpUtil.getLoginDevice()) ){
            list.add(RequestSourceEnum.Massagist.getCode());
        }
        if(RequestSourceEnum.Shop.getCode().equals(StpUtil.getLoginDevice()) ){
            list.add(RequestSourceEnum.Shop.getCode());
        }
        return list;
    }

    /**
     * 获取角色权限列表
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
//        LoginUser loginUser = LoginHelper.getLoginUser();
//        UserType userType = UserType.getUserType(loginUser.getUserType());
//        if (userType == UserType.SYS_USER) {
//            return new ArrayList<>(loginUser.getRolePermission());
//        } else if (userType == UserType.APP_USER) {
//            // 其他端 自行根据业务编写
//        }
        return new ArrayList<>();
    }
}
